<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
	array('op'=>'list','title'=>'用户平时成绩'),
);
//售后列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid'],'type'=>2);
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$list=pdo_getslice('jy_yxw_dabian_list',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['jdfen']=pdo_getsum('jy_yxw_dabian_log',array('listid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'jdfen');
			$item['ksfen']=pdo_getsum('jy_yxw_dabian_log',array('listid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'ksfen');
			$item['bsfen']=pdo_getsum('jy_yxw_dabian_log',array('listid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'bsfen');
			$item['allfen']=pdo_getsum('jy_yxw_dabian_log',array('listid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'allfen');
			$item['fenstar']=pdo_getsum('jy_yxw_dabian_log',array('listid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'fenstar');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[添加步骤]：1、添加平时成绩（同时会生成所有售后的成绩记录）；2、找到对应售后的成绩记录，一条条提交成绩成绩！
		','del_message'=>'确认删除该成绩吗？','total'=>$total,'psize'=>$psize,'del_op'=>'del','html_to'=>'list_html','list'=>array(
			array('type'=>'string','title'=>'平时成绩标题','name'=>'title'),
			array('name'=>'classid','title'=>'所属售后群','type'=>'select','options'=>'class'),
			array('type'=>'string','title'=>'总项目成绩','name'=>'jdfen'),
			array('type'=>'string','title'=>'总考勤成绩','name'=>'ksfen'),
			array('type'=>'string','title'=>'总违纪成绩','name'=>'bsfen'),
			array('type'=>'string','title'=>'总成绩','name'=>'allfen'),
			array('type'=>'string','title'=>'总评分','name'=>'fenstar'),
			array('name'=>'workerid','title'=>'评分员工','type'=>'select','options'=>'workers'),
			//array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			array('type'=>'export','action'=>'/xuesheng.dabian/export/','title'=>'导出售后成绩记录'),
			array('type'=>'href','action'=>'/xuesheng.chengji_log/','title'=>'查看售后成绩记录'),
			array('type'=>'href','action'=>'jy_yxw/xuesheng.chengji/upimg','title'=>'上传成绩签名照片'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'平时成绩标题','name'=>'title','help'=>''),
			array('name'=>'classid','width'=>15,'title'=>'所属售后群','type'=>'select','options'=>'class'),
		),
	);
	$return['class']=$this->getall('class',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['kechengs']=$this->getall('kecheng',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers']=$this->getall('worker',array('role'=>array(9,10,11,12,13),'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->member_status;
	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yxw_dabian_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array('status'=>1);
	}
	$item['hdp']=json_decode($item['hdp'],true);
	$item['typenum']=json_decode($item['typenum'],true);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回成绩列表'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'平时成绩标题','name'=>'title'),
			array('name'=>'classid','title'=>'所属售后群','type'=>'select','options'=>'class'),
			array('name'=>'workerid','title'=>'评分员工','type'=>'select','options'=>'workers'),
		)
	);
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['kechengs']=$this->getall('kecheng',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers']=$this->getall('worker',array('role'=>array(9,10,11,12,13),'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>$postdata['title'],
		'classid'=>intval($postdata['classid']),
		'workerid'=>intval($postdata['workerid']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_yxw_dabian_list',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['storeid']=$_SESSION['storeid'];
		$data['type']=2;
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_yxw_dabian_list',$data);
		$id=pdo_insertid();
		$this->model('uplog')->upclassdabian_log($id);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='upimg'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array(
			'upimgs'=>ijson_encode($post['upimgs']),
		);
		pdo_update('jy_yxw_dabian_list',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('操作成功！','','goback');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_dabian_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['upimgs']=json_decode($item['upimgs'],true);
	}else{
		exi('请先选择成绩','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'上传成绩签名照片',
	);
	$htmls['edit']=array(
		array('type'=>'images','title'=>'上传成绩签名照片','name'=>'upimgs'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	if(empty($_RQ['id'])){
		exi('请选择成绩项目！','error');
	}
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid'],'type'=>2);
	$params['listid']=intval($_RQ['id']);
	$dabian=pdo_get('jy_yxw_dabian_list',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$list=pdo_getall('jy_yxw_dabian_log',$params);
	foreach($list as &$rv){
		$rv['title']=pdo_getcolumn('jy_yxw_xuesheng',array('id'=>$rv['xueshengid'],'uniacid'=>$_SESSION['uniacid']),'title');
		$rv['fenji']=$this->danan_key[$rv['fenji']];
	}
	paixu($list,'allfen','desc');
	foreach($list as $k=>&$nv){
		$nv['key']=$nv['rank']=$k+1;
	}
	$header=array(
		'key'=>'序号',
		'title'=>'姓名',
		'jdfen'=>'毕业项目成绩',
		'ksfen'=>'口试成绩',
		'bsfen'=>'笔试成绩',
		'allfen'=>'总成绩',
		'fenji'=>'评级',
		'rank'=>'排名',
		'sign'=>'用户签名',
	);
	cfc('tools')->export2excel($header,$list,$dabian['title'].'-成绩记录');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yxw_dabian_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}